<template>
    <div>
        <h1>当前数字为:{{num}},数字是{{oddOrEven}}</h1>
        <button @click="add">+</button>
        <button @click="reduce">-</button>
        <button @click="oddNumberAdd">odd number add</button>
        <button @click="asyncAdd">async add</button>
    </div>
</template>

<script>
export default {
    name: 'DataView',
    data(){
        return {
            num: 0
        }
    },
    methods: {
        add(){
            console.log('xx');
            this.num += 1;
        },
        reduce(){
            this.num -= 1;
        },
        oddNumberAdd(){
            1 & this.num ? this.num += 1 : '';
        },
        asyncAdd(){
            setTimeout(() => {
                this.num += 1;
            },1000);
        }
    },
    computed: {
        oddOrEven(){
            return 1 & this.num  ? '奇数' : '偶数';
        }
    }
}
</script>